package com;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
public class MyInit implements CommandLineRunner,ApplicationRunner {

    @Override
    public void run(String... args) throws Exception {
        //初始化工作。。。
        System.out.println("CommandLineRunner--------");
        for (String arg : args) {
            System.out.println("arg = " + arg);
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("ApplicationRunner--------");
        List<String> nonOptionArgs = args.getNonOptionArgs();
        for (String nonOptionArg : nonOptionArgs) {
            System.out.println("nonOptionArg = " + nonOptionArg);
        }
        Set<String> optionNames = args.getOptionNames();
        for (String optionName : optionNames) {
            System.out.println("optionName = " + optionName);

            List<String> optionValues = args.getOptionValues(optionName);
            for (String optionValue : optionValues) {
                System.out.println("optionValue = " + optionValue);
            }
            System.out.println("===================");
        }
    }
}
